package com.rachel.materialdemo.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.rachel.materialdemo.R;
import com.rachel.materialdemo.bean.ViewBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhengshaorui on 2017/8/22.
 */

public class ViewPagerViewholder extends ViewHolderParent<ViewBean> {
    private ViewPager mViewPager;
    private Context mContext;
    public ViewPagerViewholder(Context context,View itemView) {
        super(itemView);
        mContext = context;
        mViewPager = (ViewPager) itemView.findViewById(R.id.viewpager);
        List<View> views = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.viewpager_item,null);
            ImageView imageView = (ImageView) view.findViewById(R.id.viewpager_img);
            imageView.setImageResource(R.mipmap.image5);
            views.add(view);
        }
        mViewPager.setAdapter(new BannerAdapter(views));
    }



    class BannerAdapter extends PagerAdapter {

        List<View> list;
        public BannerAdapter(List<View> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = list.get(position);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }


}
